from app.celery import flask_app_context
from flask import jsonify, current_app
from flask_jwt_extended import jwt_required
from flask_jwt_extended import get_jwt, get_jwt_identity
from app.libs.redprint import RedPrint
from app.celery.action import demo_actions

api = RedPrint('demo')


@api.route('/jwt', methods=['GET'])
@jwt_required()
def jwt():
    id = get_jwt_identity()
    jwt = get_jwt()
    print(jwt)
    return jsonify(id=id, jwt=jwt), 200


@api.route('/debug-sentry', methods=['GET'])
def trigger_error():
    try:
        division_by_zero = 1 / 0
        # demo_actions.do_test_sentry.delay()
    except ZeroDivisionError:
        current_app.logger.error("可用性任务628485315fbd6e1afd72f899结果详情为空， 任务处理状态设置为失败：{'detail_v6': }")
    return jsonify({"message": "sentry test"})


# @api.route('/test-flask-context', methods=['GET'])
# @jwt_required()
# def test_flask_app_context():
#     """
#     测试相加
#     :return:
#     """
#     result = flask_app_context.delay()
#     return result.get(timeout=2).replace('<Config', '')
